package org.sojex.photo.bean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.sojex.photo.util.GlobalData;

public class CookBook {// 总谱
	public ArrayList<Cooks> cookBook = new ArrayList<Cooks>();
	public int id(){
		return 10001;
	}

	public String BeanToString() {
		StringBuffer sb = new StringBuffer();
		for(Cooks cooks:cookBook){
			sb.append(cooks.cooksName);
			sb.append(GlobalData.SPLIT3);
			sb.append(cooks.cooksUrl);
			sb.append(GlobalData.SPLIT2);
			for(CookBean cookBean : cooks.cooks){
				sb.append(cookBean.name);
				sb.append(GlobalData.SPLIT3);
				sb.append(cookBean.url);
				sb.append(GlobalData.SPLIT3);
				sb.append(GlobalData.SPLIT4);
			}
			sb.append(GlobalData.SPLIT2);
			
			sb.append(GlobalData.SPLIT1);
		}
			
//		for (Cooks cooks : cookBook) {
//			sb.append(cooks.cooksName);
//			sb.append(GlobalData.SPLIT1);
//			sb.append(GlobalData.pictureBasePath+cooks.cooksName+".png");
//			sb.append(GlobalData.SPLIT2);
//			for(CookBean cookBean:cooks.cooks){
//				sb.append(cookBean.name);
//				sb.append(GlobalData.SPLIT1);
//				sb.append(GlobalData.pictureBasePath+cookBean.name+".png");
//				sb.append(GlobalData.SPLIT2);
//			}
//		}
		return sb.toString();
	}
	static public CookBook StringToBean(String beanStr){
		CookBook cookBook = new CookBook();
		Cooks cooks = null;
		CookBean cookBean = null;
		
		String[] BookStr = beanStr.split(GlobalData.SPLIT1);
		for(String str1 : BookStr){
			cooks = new Cooks();
			String[]cookstr = str1.split(GlobalData.SPLIT2);
			String[]node = cookstr[0].split(GlobalData.SPLIT3);
			cooks.cooksName = node[0];
			cooks.cooksUrl = node[1];
			cooks.cooksPath = GlobalData.pictureBasePath+node[0]+".png";
			String[]node1 = cookstr[1].split(GlobalData.SPLIT4);
			for(String caiStr:node1){
				cookBean = new CookBean();
				String[] caiInfo = caiStr.split(GlobalData.SPLIT3);
				cookBean.name = caiInfo[0];
				cookBean.url = caiInfo[1];
				cookBean.uri = GlobalData.pictureBasePath+caiInfo[0]+".png";
				cooks.cooks.add(cookBean);
			}
			cookBook.cookBook.add(cooks);
		}
		
		
//		String[] cookBookList = str.split(GlobalData.SPLIT2);
//		for(String str1:cookBookList){
//			String[]str2 =str.split(GlobalData.SPLIT1);
//			GlobalData.ImageUri.put(str2[0], str2[1]);		
//
//		}
		return cookBook;
	}
}
